document.write(
    '<script type="text/javascript" src="/guanglianstatic/js/jquery-3.6.0.min.js"></script>' +
    '<script type="text/javascript" src="/guanglianstatic/js/header.min.js"></script>' +
    '<script type="text/javascript" src="/guanglianstatic/js/bootstrap.min.js"></script>' +
    '<script type="text/javascript" src="/guanglianstatic/js/jq-paginator.min.js"></script>' +
    "<script type=\"text/javascript\">\n" +
    "    $(\"#site-header\").load(\"/nav\");\n" +
    "    $(\"#site-footer\").load(\"/footer\");\n" +
    "</script>\n"

)
var server = 'http://localhost:8080'

//时间格式转换函数：
Date.prototype.format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1,                 //月份
        "d+": this.getDate(),                    //日
        "h+": this.getHours(),                   //小时
        "m+": this.getMinutes(),                 //分
        "s+": this.getSeconds(),                 //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds()             //毫秒
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
};


function postJSON(url, data, callback) {
    if ($.isFunction(data)) {
        callback = data;
        data = undefined;
    }
    return $.ajax({
        url: server + url,
        type: "POST",
        data: data,
        success: function (res) {
            callback(res);

        },
        dataType: "json",
        error: function (jqXHR, textStatus, errorMsg) {
            callback(errorMsg);
        }
    });
}

//参数校验
function vaildeParam(param) {
    if (typeof param == 'undefined') {
        return false;
    }
    if (undefined === param) {
        return false
    }
    if (null == param) {
        return false;
    }
    if (param.length === 0) {
        return false;
    }
    return true;
}

//判断邮箱
function vaildeEmail(emailStr) {
    var patten = /^([a-zA-Z0-9]+[_|_|\-|.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    return patten.test(emailStr);
}

/**
 * 判断手机号是否正确
 * @param mobile
 */
function vaildeMobile(mobile) {
    var reg = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
    return reg.test(mobile);

};

//商品模板
function renderTable(data,title) {
    var html = "";
    $(".product-list-main").empty();
    $.each(data, function (index, item) {
        html = $(' <div class="product-list-item">\n' +
            '                        <a href="/productDetails?id=' + item.id + '+&title='+ title +'" target="_self" class="product-img-item" style="cursor: pointer;">\n' +
            '                            <img src="' + item.pic + '">\n' +
            '                        </a>\n' +
            '                        <div class="product-title-item">' + item.title + '</div>\n' +
            '                        <div class="product-menu-tag">' + item.series_name + '</div>\n' +
            '                        <div class="product-menu-tag" style="padding: 22px 0 22px 32px;">\n' +
            '                            <a href="/productDetails?id=' + item.id + '+&title='+ title +'" target="_self"> 了解更多 <i class="el-icon-arrow-right"></i></a>\n' +
            '                        </div>\n' +
            '                        <div class="product-tips"></div>\n' +
            '                    </div>')

        $(".product-list-main").append(html);

    })
}

//商品分页
function pagination(data, currentPage, title) {
    postJSON(api, data, function (res) {
        if (res.data.length > 0) {
            $(".pagination-warp").show();
            $(".count-tag span").text(res.count);
            $.jqPaginator("#pagination1", {
                totalPages: Math.ceil(res.count / 6),
                visiblePages: 6,
                currentPage: currentPage,
                first: '<li class="first"><a href="javascript:void(0);">首页</a></li>',
                prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
                next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
                last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
                page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
                onPageChange: function (page) {
                    // data.offset = page;
                    console.log(page);
                    var data = {
                        "page": page,
                        "title": title,
                    }
                    postJSON(api, data, function (res) {
                        renderTable(res.data,title);
                    })
                }
            })
        } else {
            $(".product-list-main").empty();
            $(".pagination-warp").hide();
            $(".product-list-main").html("<div class=\"product-tag-item\">暂时还没有产品</div>");
        }
    })
}


//公告模板
function announcementRenderTable(data) {
    $(".recruitmentAd-msg").empty();
    var html = '';
    $.each(data, function (index, item) {
        var curTime = new Date(item.modify_date).format("yyyy-MM-dd");
        if (parseInt(item.hotspot_flag) === 1) {
            html = $('<li>\n' +
                '                <a href="/news/socialResponsibility?id=' + item.id + '">' + item.title + '<span class="recruitmentAd-tag">热点</span></a>\n' +
                '                <span>' + curTime + '</span>\n' +
                '            </li>')
        } else {
            html = $('<li>\n' +
                '                <a href="/news/socialResponsibility?id=' + item.id + '">' + item.title + '</a>\n' +
                '                <span>' + curTime + '</span>\n' +
                '            </li>')
        }

        $(".recruitmentAd-msg").append(html);

    });
}

//公告分页
function announcementPagination(currentPage, data) {
    postJSON(api, data, function (res) {
        if (res.data.length > 0) {
            $(".pagination-warp").show();
            $(".count-tag span").text(res.count);
            $.jqPaginator("#pagination1", {
                totalPages: Math.ceil(res.count / 6),
                visiblePages: 10,
                currentPage: currentPage,
                first: '<li class="first"><a href="javascript:void(0);">首页</a></li>',
                prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
                next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
                last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
                page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
                onPageChange: function (page) {
                    // data.offset = page;
                    console.log(page);
                    var data = {
                        "page": page,
                    }
                    postJSON(api, data, function (res) {
                        announcementRenderTable(res.data);
                    })
                }
            })
        } else {
            $(".recruitmentAd-msg").empty();
            $(".pagination-warp").hide();
            $(".recruitmentAd-msg").append("暂时还有没招聘信息")
        }

    })

}